define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/member/index',
                    add_url: 'user/member/add',
                    edit_url: 'user/member/edit',
                    del_url: 'user/member/del',
                    multi_url: 'user/member/multi',
                    table: 'member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'member_id',
                sortName: 'member_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'member_id', title: __('Member_id')},
                        {field: 'user_name', title: __('User_name'),visible:false},
                        {field: 'real_name', title: __('Real_name'),visible:false},
                        {field: 'password', title: __('Password'),visible:false},
                        {field: 'referrer_id', title: __('Referrer_id'),visible:false},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'email', title: __('Email')},
                        {field: 'password_trade', title: __('Password_trade'),visible:false},
                        {field: 'password_trade_message', title: __('Password_trade_message'),visible:false},
                        {field: 'card_type', title: __('Card_type'),visible:false},
                        {field: 'card_id', title: __('Card_id'),visible:false},
                        {field: 'currency_exchange_id', title: __('Currency_exchange_id'),visible:false},
                        {field: 'exchange.currency_name_cn', title: __('Currency_name_cn')},
                        {field: 'reg_ip', title: __('Reg_ip'),visible:false},
                        {field: 'reg_time', title: __('Reg_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'login_ip', title: __('Login_ip'),visible:false},
                        {field: 'login_time', title: __('Login_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'vip_level', title: __('Vip_level')},
                        {field: 'vip_end_time', title: __('Vip_end_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'head_ico', title: __('Head_ico'),visible:false},
                        {field: 'country', title: __('Country'),visible:false},
                        {field: 'province', title: __('Province'),visible:false},
                        {field: 'city', title: __('City'),visible:false},
                        {field: 'is_lock', title: __('Is_lock'), visible:false, searchList: {"1":__('未锁定'),"2":__('锁定')}},
                        {field: 'is_lock_text', title: __('Is_lock'), operate:false},
                        {field: 'status', title: __('Status'), visible:false, searchList: {"1":__('未认证'),"2":__('已认证'),"3":__('认证失败')}},
                        {field: 'status_text', title: __('Status'), operate:false},
                        {field: 'country_id', title: __('Country_id'),visible:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});